//
//  CabinetAppDelegate.h
//  Cabinet
//
//  Created by Florent Montsegur on 12/03/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "ConsultationsController.h"
#import "Waiting.h"
#import "Vaccin.h"
#import "GestionPersonController.h"
#import "EtatConsultationController.h"
#import "VaccinationController.h"
#import "ImpayesController.h"


@interface CabinetAppDelegate : NSObject <NSApplicationDelegate,NSTableViewDelegate,NSTextViewDelegate,IEnregistrerNotifiable> {
@private
    NSWindow *__unsafe_unretained window;
    NSPersistentStoreCoordinator *__persistentStoreCoordinator;
    NSManagedObjectModel *__managedObjectModel;
    NSManagedObjectContext *__managedObjectContext;
    
    NSTableView *__unsafe_unretained mConsultations;
    NSTableView *__unsafe_unretained mImpayes;
    
    NSTextField *__unsafe_unretained mConsDay;
    NSTextField *__unsafe_unretained mConsNum;
    NSDatePicker *__unsafe_unretained mConsDate;
    NSTextField *__unsafe_unretained mConsNom;
    NSTextField *__unsafe_unretained mConsPrenom;
    NSTextField *__unsafe_unretained mConsDiag;
    NSTextField *__unsafe_unretained mConsRef;
    NSTextView *__unsafe_unretained mConsTraitement;
    NSTextField *__unsafe_unretained mConsMoyenPaiement;
    NSTextField *__unsafe_unretained mConsActe;
    NSTextField *__unsafe_unretained mConsSomme;
    NSTextView *__unsafe_unretained mConsInfos;
    NSTextField *__unsafe_unretained mTotalImpayes;
    
    NSButton *__unsafe_unretained mConsPaye;
    NSButton *__unsafe_unretained mRenouvellement;
    
    NSButton *__unsafe_unretained mSearchPerson;
    NSButton *__unsafe_unretained mSearchDiagnostic;
    
    NSButton *__unsafe_unretained mCheques;
    NSButton *__unsafe_unretained mEspeces;
    NSButton *__unsafe_unretained mAld;
    NSButton *__unsafe_unretained mCmu;
    NSButton *__unsafe_unretained mArt;
    NSButton *__unsafe_unretained mAt;
    NSButton *__unsafe_unretained mVacciner;
    
    NSButton *__unsafe_unretained mEnregistrer;
    NSButton *__unsafe_unretained mNouvelActe;
    NSMenuItem *__unsafe_unretained mMenuNouvelActe;
    
    NSDatePicker *__unsafe_unretained mNaissance;
    NSButton *__unsafe_unretained mTraitantMe;
    NSTextField *__unsafe_unretained mAge;
    
    NSButtonCell *__unsafe_unretained mFeuilleNone;
    NSButtonCell *__unsafe_unretained mFeuilleDone;
    NSButtonCell *__unsafe_unretained mFeuilleGiven;   
    
    
    
    GestionPersonController *mGestionPersonWnd;
    EtatConsultationController *mEtatConsultationWnd;
    VaccinationController *mVaccinationWnd;
    
    ConsultationsController *mConsulationCtrl;
    ImpayesController *mImpayesCtrl;
    
    ConsultationViewController * mConsultationWnd;
    
    NSEntityDescription *mConsultationEntity;
    NSEntityDescription *mPersonEntity;
    NSEntityDescription *mDiagnosticEntity;
    
    NSEntityDescription *mRangEntity;
    NSEntityDescription *mVaccinEntity;
    NSEntityDescription *mVaccinationEntity;
}

@property (unsafe_unretained) IBOutlet NSWindow *window;
@property (unsafe_unretained) IBOutlet NSTableView *mConsultations;
@property (unsafe_unretained) IBOutlet NSTableView *mImpayes;

@property (unsafe_unretained) IBOutlet NSTextField *mConsDay;
@property (unsafe_unretained) IBOutlet NSTextField *mConsNum;
@property (unsafe_unretained) IBOutlet NSDatePicker *mConsDate;
@property (unsafe_unretained) IBOutlet NSTextField *mConsNom;
@property (unsafe_unretained) IBOutlet NSTextField *mConsPrenom;
@property (unsafe_unretained) IBOutlet NSTextField *mConsDiag;
@property (unsafe_unretained) IBOutlet NSTextField *mConsRef;
@property (unsafe_unretained) IBOutlet NSTextView *mConsTraitement;
@property (unsafe_unretained) IBOutlet NSTextField *mConsMoyenPaiement;
@property (unsafe_unretained) IBOutlet NSTextField *mConsActe;
@property (unsafe_unretained) IBOutlet NSTextField *mConsSomme;
@property (unsafe_unretained) IBOutlet NSTextView *mConsInfos;
@property (unsafe_unretained) IBOutlet NSTextField *mTotalImpayes;

@property (unsafe_unretained) IBOutlet NSButton *mConsPaye;
@property (unsafe_unretained) IBOutlet NSButton *mRenouvellement;
@property (unsafe_unretained) IBOutlet NSButton *mEnregistrer;
@property (unsafe_unretained) IBOutlet NSButton *mNouvelActe;
@property (unsafe_unretained) IBOutlet NSMenuItem *mMenuNouvelActe;

@property (unsafe_unretained) IBOutlet NSButton *mSearchPerson;
@property (unsafe_unretained) IBOutlet NSButton *mSearchDiagnostic;
@property (unsafe_unretained) IBOutlet NSButton *mCheques;
@property (unsafe_unretained) IBOutlet NSButton *mEspeces;
@property (unsafe_unretained) IBOutlet NSButton *mAld;
@property (unsafe_unretained) IBOutlet NSButton *mCmu;
@property (unsafe_unretained) IBOutlet NSButton *mArt;
@property (unsafe_unretained) IBOutlet NSButton *mAt;
@property (unsafe_unretained) IBOutlet NSButton *mVacciner;

@property (unsafe_unretained) IBOutlet NSDatePicker *mNaissance;
@property (unsafe_unretained) IBOutlet NSButton *mTraitantMe;
@property (unsafe_unretained) IBOutlet NSTextField *mAge;

@property (unsafe_unretained) IBOutlet NSButtonCell *mFeuilleNone;
@property (unsafe_unretained) IBOutlet NSButtonCell *mFeuilleDone;
@property (unsafe_unretained) IBOutlet NSButtonCell *mFeuilleGiven;

@property (nonatomic, strong, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, strong, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext;


// NSTableViewDelegate
- (void) tableViewSelectionDidChange:(NSNotification *)aNotification;
- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation;

- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector;
- (void)textDidChange:(NSNotification *)aNotification;

- (IBAction)saveAction:sender;
- (IBAction)searchPersonAction:sender;
- (IBAction)searchDiagnosticAction:sender;
- (IBAction)patientManagement:sender;

- (IBAction)newAction:sender;

- (IBAction)vaccinerAction:sender;
- (IBAction)okAction:sender;
- (IBAction)annulerAction:sender;
- (IBAction)dateAction:sender;
- (IBAction)importerConsultationAction:sender;
- (IBAction)importerVaccinationAction:sender;
- (IBAction)renouvellementAction:sender;

- (IBAction)rechercherConsultationAction:sender;

- (IBAction)chequeAction:sender;
- (IBAction)especesAction:sender;
- (IBAction)aldAction:sender;
- (IBAction)cmuAction:sender;
- (IBAction)atAction:sender;
- (IBAction)artAction:sender;

- (IBAction)consultationDoubleClickAction:(id)sender;

- (IBAction)impayesDoubleClickAction:(id)sender;

// type 1 pour consultation, type 2 pour vaccin
- (void)importerAction:(int)aTypeFile;
- (void)emptyFields;
- (void)fillConsultation:(Consultation*)aConsultation;
- (void)afficherImpayes:(Person*) aPerson;

- (NSInteger)getNbDayConsultations;
- (NSString*)GetMoyenPayement:(NSString*) aMode;

- (void) showMessage:(NSString*)aMessage;
- (BOOL) personExists:(NSString*)aNom andPrenom:(NSString*)aPrenom;
- (BOOL) addExists:(NSString*)aNom andPrenom:(NSString*)aPrenom;

- (NSString *) formatInput:(NSTextField*)aTextField;
- (NSString*) formatTVInput:(NSTextView*)aTextView;

- (BOOL) importCSVVaccinationLine:(NSString*)aLine;
- (BOOL) importCSVConsultationLine:(NSString*)aLine;
- (void) showDayName;
- (void) showPerson:(Person*)aPerson; 

- (BOOL) readFromPath:(NSString *)absolutePath withType:(int)aTypeFile;

- (Person*) getPersonForVaccination;
- (Person*) getPerson:(NSString*)aNom andPrenom:(NSString*)aPrenom;
- (void) showNbConsultations;

- (void) addRang:(NSString*)aRang;
- (Vaccin*) getVaccin:(NSString*)aNomVaccin withCode:(NSNumber*)aCode;

- (BOOL) getNextValue:(NSScanner*)aScanner andCharSet:(NSCharacterSet*)aSeparator andString:(NSString**)aString;
- (void) runImport:(Waiting*)aPanel;

- (void) fillConsultation:(Consultation*)aConsultation at:(NSDate*)aDate 
                 firstame:(NSString*)aFirstame lastame:(NSString*)aLastname
                     diag:(NSString*)aDiag ref:(NSString*)aRef obs:(NSString*)aObs
                 payement:(NSString*)aPayement acte:(NSString*)aActe
                   donnee:(NSNumber*)aDonnee payee:(NSNumber*)aPayee
               traitement:(NSString*)aTrait prix:(NSDecimalNumber*)aPrix
                medecin:(NSInteger) aTraitant naissance:(NSDate*) aNaissance comments:(NSString*)aComments;

- (void) setEnableControlsState:(BOOL)aValue;
- (NSInteger)calculAge:(NSDate *)aNaissance;
- (void) addDiagnostic:(NSString*)aDiagnostic;

// IEnregistrerNotifiable
-(void) Enregistre;

@end
